// pages/restaurant/shop/component/shopCoupon/shopCoupon.js
import { couponList, } from "../../../api/coupon"
const app = getApp();
const util = require('../../../utils/util.js')

Component({
  /**
   * 组件的属性列表
   */
  properties: {
      shopCouponList: {
          type: Array,
          value: '',
        },
  },

  /**
   * 组件的初始数据
   */
  data: {
    shopCouponList:[]
  },

  lifetimes: {
    attached() {
      var _this = this
      // _this.getcouponList()
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
     //查询平台优惠券列表
     getcouponList(){
      let _this = this
      let params = {
          mchId:app.globalData.mchId
      }
      couponList(params).then(
          (res)=>{
              console.info("优惠券信息------")
              console.info(res)
              if (res.type == 'success') {
                let coupons = res.data.data
                if(coupons.length > 0){
                  coupons.map((item)=>{
                    if(item.status == 1){
                      item.endDate = util.datetimeFormat(item.endDate)
                    }
                  })
                }
                  _this.setData({
                      shopCouponList :coupons   
                  })
              }
          }
      ).catch( )
  },
  }
})
